using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

public class OpacityController : MonoBehaviour
{
// 定义数据类
    [System.Serializable]
    public class OpacityData
    {
        public float ExpansionSpeed;
        public float Thickness;
        public float MaxRadius;
        public float FadeWidth;
        public float Falloff;
    }
    private OpacityData opacityData;

    // 文件路径
    private string filePath;

    void Start()
    {
        // 获取文件路径，StreamingAssets 目录下
        filePath = Path.Combine(Application.streamingAssetsPath, "RippleData.json");

        // 读取 JSON 数据
        ReadJsonData();
    }

    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.R))
        {
            ReadJsonData();
        }
    }

    void ReadJsonData()
    {
        Debug.Log("开始读取文件");
        if (File.Exists(filePath))
        {
            Debug.Log("文件存在");
            // 读取文件内容
            string json = File.ReadAllText(filePath);

            // 使用 JsonUtility 从 JSON 字符串反序列化数据
            opacityData = JsonUtility.FromJson<OpacityData>(json);

            // 输出数据
            Debug.Log("ExpansionSpeed: " + opacityData.ExpansionSpeed);
            Debug.Log("Thickness: " + opacityData.Thickness);
            Debug.Log("MaxRadius: " + opacityData.MaxRadius);
            Debug.Log("FadeWidth: " + opacityData.FadeWidth);
            Debug.Log("Falloff: " + opacityData.Falloff);
            
            
            
            GlobalData.ExpansionSpeed = opacityData.ExpansionSpeed;
            GlobalData.Thickness = opacityData.Thickness;
            GlobalData.MaxRadius = opacityData.MaxRadius;
            GlobalData.FadeWidth = opacityData.FadeWidth;
            GlobalData.Falloff = opacityData.Falloff;
            // GlobalData.ScaleSpeed = opacityData.ScaleSpeed;
        }
        else
        {
            Debug.LogError("JSON 文件未找到！");
        }
    }
}
